import { Singleton } from "../../meshTools/Singleton";
import { AutoOrRoom } from "../hall/HallAutoController";
import { CurTask, InviteInfo, LoginData, NoticeStartGame, ObstacleBlock, RoomUser } from "./GameBean";

export class GlobalBean extends Singleton{

    loginData:LoginData = null;  //用户数据

    public autoAndRoom = AutoOrRoom.AUTO; //当前选中的是哪种游戏模式
    public players = 2;  //玩家人数 默认两个人
    public ticketsNum = 0;  //门票价格


     //这个数据是游戏开始之后 服务器返回的数据
    public noticeStartGame: NoticeStartGame //开始游戏的数据

    public inviteInfo: InviteInfo;//这个是创建完房间返回的数据
    

    cleanData(){
        this.noticeStartGame = null
 
        this.inviteInfo = null
    }

     //调整 users 数据的展示顺序把自己的数据调整到第一位， 并不是调整座位数据
     adjustUserData(): RoomUser[] {
        let user: RoomUser[] = this.noticeStartGame.users;
        const index = user.findIndex((item) => item.userId === GlobalBean.GetInstance().loginData.userInfo.userId);
        if (index !== -1) {
            const element = this.noticeStartGame.users.splice(index, 1)[0];
            user.unshift(element);
            return user;
        }
    }

    getQueue(){
        return BlockingQueue.getInstance<number>(1000);
    }

}